package com.atguigu.gulimallcart.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class MyThreadConfig {

    /**
     * 自定义线程池的参数
     * @param threadPoolProperties 绑定的配置文件
     * @return
     */
    @Bean
    public ThreadPoolExecutor myTheradPoolExecutor(MyThreadPoolProperties threadPoolProperties){

       return new ThreadPoolExecutor(threadPoolProperties.getCorePoolSize(),
               threadPoolProperties.getMaximumPoolSize(),
               threadPoolProperties.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(2000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

    }


}
